<template>
    <div class="search-list">
        <ul v-if="searchlist.length != 0">
            <li v-for="item in searchlist" :key="item.id">
                <router-link :to="{ name: 'detail', query: { id: item.bookId, title: item.title } }">
                    <div class="img-box">
                        <img v-if="item.cover" :src="item.cover" alt="" />
                        <!-- <img v-else src="@/assets/jiazai.jpg" alt="" /> -->
                    </div>
                    <div class="content-box">
                        <p class="book-name">{{ item.title }}</p>
                        <p class="author">{{ item.author }}</p>
                        <p class="book-detail">{{ item.summary }}</p>
                    </div>
                </router-link>
            </li>
        </ul>
        <div class="sousuo" v-else>正在搜索中...</div>
    </div>
</template>

<script>
import { bookSearch } from "@/api/found";
export default {
    data() {
        return {
            searchlist: [],
        };
    },
    directives: {
        img: {
            inserted(el) {
                el.src = "@/assets/jiazai.jpg";
            },
        },
    },
    methods: {
        getSearchList() {
            let data = {
                keyword: this.$route.query.value,
            };
            bookSearch({ data }).then((res) => {
                // console.log(res);
                this.searchlist = res.data.books;
                // console.log(res.data.books);
            });
        },
    },
    beforeRouteUpdate(to, from, next) {
        // console.log(to);
        next();
        this.getSearchList();
    },
    beforeRouteEnter(to, from, next) {
        next((vm) => {
            vm.getSearchList();
        });
    },
    // created() {
    //     this.getSearchList();
    // },
};
</script>

<style lang="scss" scoped>
.search-list {
    padding: 60px 0 10px;
    width: 100%;
    ul {
        width: 100%;
        // height: 100px;
        a,
        li {
            // border: 1px solid #000;
            padding: 5px 0;
            width: 100%;
            height: 100px;
            margin-bottom: 15px;
            display: flex;
            .img-box {
                width: 23%;
                height: 100%;
                img {
                    width: 100%;
                    height: 100%;
                }
            }

            .content-box {
                padding-left: 8px;
                width: 77%;
                height: 100px;
                .book-name {
                    padding: 0px 0px 6px;
                    font-size: 13px;
                    font-weight: 500;
                    color: #000;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    white-space: nowrap;
                }
                .author {
                    padding-bottom: 8px;
                    font-size: 12px;
                    color: #656565;
                }
                .book-detail {
                    height: 49px;
                    line-height: 17px;
                    font-size: 12px;
                    color: #999;
                    overflow: hidden;
                    text-overflow: ellipsis;
                    // white-space: 3;
                    -webkit-line-clamp: 3;
                    display: -webkit-box;
                    -webkit-box-orient: vertical;
                }
            }
        }
    }

    .sousuo {
        width: 100%;
        text-align: center;
        padding-top: 50px;
    }
}
</style>
